package com.rqbl.controller;


import com.rqbl.entity.Reply;
import com.rqbl.entity.User;
import com.rqbl.service.ReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author bruce
 * @since 2024-07-19
 */
@Controller
@RequestMapping("/reply")
public class ReplyController {

    @Autowired
    private ReplyService replyService;

    @RequestMapping("/addReply")
    @ResponseBody
    public String addReply(String text, Integer cid, HttpSession session){
        User user = (User) session.getAttribute("user");
        return replyService.addReply(text, cid, user.getUid()).toString();
    }

    @RequestMapping("/getReplyByCid")
    @ResponseBody
    public List<Reply> getReplyByCid(Integer cid,Integer page,Integer limit){
        return replyService.getReplyByCid(cid,page,limit);
    }

    @RequestMapping("/forwardReplyByCid")
    public String forwardReplyByCid(Integer cid ,HttpServletRequest request){
        System.out.println("当前的cid为"+cid);
        request.setAttribute("cid", cid);
        return "forward:/WEB-INF/jsp/reply.jsp";
    }

}
